/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ultrasoft.farmasoft.domain;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name = "credititem")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Credititem.findAll", query = "SELECT c FROM Credititem c"),
    @NamedQuery(name = "Credititem.findByAccountReceivableId", query = "SELECT c FROM Credititem c WHERE c.credititemPK.accountReceivableId = :accountReceivableId"),
    @NamedQuery(name = "Credititem.deleteByAccountReceivableIdByPackageIdByItemId", query = "DELETE FROM Credititem c WHERE c.credititemPK.accountReceivableId = :accountReceivableId AND c.credititemPK.packageId = :packageId AND c.credititemPK.itemId = :itemId"),
    @NamedQuery(name = "Credititem.findByAccountReceivableIdByPackageIdByItemId", query = "SELECT c FROM Credititem c WHERE c.credititemPK.accountReceivableId = :accountReceivableId AND c.credititemPK.packageId = :packageId AND c.credititemPK.itemId = :itemId"),
    @NamedQuery(name = "Credititem.findByPackageIdByItemId", query = "SELECT c FROM Credititem c WHERE c.credititemPK.packageId = :packageId AND c.credititemPK.itemId = :itemId"),
    @NamedQuery(name = "Credititem.findByPackageId", query = "SELECT c FROM Credititem c WHERE c.credititemPK.packageId = :packageId"),
    @NamedQuery(name = "Credititem.findByItemId", query = "SELECT c FROM Credititem c WHERE c.credititemPK.itemId = :itemId")})
public class Credititem implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected CredititemPK credititemPK;
    @JoinColumns({
        @JoinColumn(name = "packageId", referencedColumnName = "packageId", insertable = false, updatable = false),
        @JoinColumn(name = "itemId", referencedColumnName = "itemId", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Item item;
    @JoinColumn(name = "accountReceivableId", referencedColumnName = "accountReceivableId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Accountreceivable accountreceivable;

    public Credititem() {
    }

    public Credititem(CredititemPK credititemPK) {
        this.credititemPK = credititemPK;
    }

    public Credititem(int accountReceivableId, int packageId, int itemId) {
        this.credititemPK = new CredititemPK(accountReceivableId, packageId, itemId);
    }
    
    public Credititem(Accountreceivable accountReceivable,Item item) {
        this.credititemPK = new CredititemPK(accountReceivable.getAccountReceivableId(),item.getItemPK().getPackageId(),item.getItemPK().getItemId());
    }

    public CredititemPK getCredititemPK() {
        return credititemPK;
    }

    public void setCredititemPK(CredititemPK credititemPK) {
        this.credititemPK = credititemPK;
    }

    public Item getItem() {
        return item;
    }

    public void setItem(Item item) {
        this.item = item;
    }

    public Accountreceivable getAccountreceivable() {
        return accountreceivable;
    }

    public void setAccountreceivable(Accountreceivable accountreceivable) {
        this.accountreceivable = accountreceivable;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (credititemPK != null ? credititemPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Credititem)) {
            return false;
        }
        Credititem other = (Credititem) object;
        if ((this.credititemPK == null && other.credititemPK != null) || (this.credititemPK != null && !this.credititemPK.equals(other.credititemPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.ultrasoft.farmasoft.domain.Credititem[ credititemPK=" + credititemPK + " ]";
    }
    
}
